<?php

namespace App\Modules\Admin\Entities\Rabc;

use App\Models\Model;

class AdminMenu extends Model
{
    protected $primaryKey = 'menu_id';
    protected $is_delete = 0;

    public function getAllMenus()
    {
        $first = ['menu_id','parent_id','menu_name','vue_icon','vue_name','vue_path','vue_component','vue_redirect','is_hidden','api_url','api_method'];

        return $this->orderBy('menu_sort', 'ASC')->get($first);
    }

    public function getSelectLists()
    {
        $first = ['menu_id','menu_id as value','parent_id','menu_name as  label','menu_name'];
        return list_to_tree($this->orderBy('menu_sort', 'ASC')->get($first)->toArray(),'menu_id','parent_id','children');
    }

    public function getMenusByIds(array $menu_ids)
    {
        return $this->whereIn('menu_id', $menu_ids)
            ->orderBy('menu_sort', 'ASC')
            ->get();
    }

    public function getMenusByIdsForRabc(array $menu_ids)
    {
        return $this->whereIn('menu_id', $menu_ids)->where('api_url', '<>', '')->pluck('api_method', 'api_url');
    }
}
